/* GUI CONVERTED from repkis.p (converter v1.76) Sun Aug 25 20:59:52 2002 */
/* repkis.p - REPETITIVE PICKLIST ISSUE                                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.18.2.8 $                                                               */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 09/06/92   BY: emb *G071*                */
/* Revision: 7.3      Last edit:     09/27/93   By: jcd *G247*                */
/* REVISION: 7.4      LAST MODIFIED: 07/22/93   BY: pcd *H039*                */
/*                                   08/27/94   BY: bcm *GL62*                */
/*                    LAST MODIFIED: 09/15/94   by: slm *GM63*                */
/*                                   11/06/94   by: rwl *GO29*                */
/*                                   11/08/94   by: srk *GO05*                */
/* REVISION: 8.5      LAST MODIFIED: 10/24/94   BY: mwd *J034*                */
/*                    LAST MODIFIED: 11/22/94   By: qzl  *GO59*               */
/*                    LAST MODIFIED: 12/09/94   BY: taf *J038*                */
/*                    LAST MODIFIED: 12/21/94   By: WUG  *G09R*               */
/*                    LAST MODIFIED: 12/28/94   BY: ktn *J041*                */
/*                    LAST MODIFIED: 05/17/95   BY: sxb *J04D*                */
/*                    LAST MODIFIED: 06/21/95   BY: qzl  *G0QJ*               */
/*                    LAST MODIFIED: 08/17/95   BY: qzl  *F0TC*               */
/*                                   05/01/96   BY: jzs  *H0KR*               */
/* REVISION: 8.6      LAST MODIFIED: 07/01/96   BY: bjl  *K001*               */
/*                    LAST MODIFIED: 07/16/96   BY: kxn  *J0QX*               */
/* REVISION: 8.5    LAST MODIFIED: 08/28/96 BY: *G2D7* Julie Milligan         */
/* REVISION: 8.6    LAST MODIFIED: 09/11/96 BY: *G2DP* Julie Milligan         */
/* REVISION: 8.6    LAST MODIFIED: 10/18/96 BY: *H0NG* Murli Shastri          */
/* REVISION: 8.6    LAST MODIFIED: 10/31/96 BY: *G2HG* Julie Milligan         */
/* REVISION: 8.5    LAST MODIFIED: 12/17/97 BY: *J287* Santhosh Nair          */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane              */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan             */
/* REVISION: 8.6E   LAST MODIFIED: 06/18/98 BY: *J2PD* A. Licha               */
/* REVISION: 8.6E   LAST MODIFIED: 08/25/98 BY: *L07B* Jean Miller            */
/* REVISION: 8.6E   LAST MODIFIED: 09/16/98 BY: *L09B* Jean Miller            */
/* REVISION: 8.6E   LAST MODIFIED: 10/14/98 BY: *J32C* Thomas Fernandes       */
/* REVISION: 9.1    LAST MODIFIED: 10/27/99 BY: *N04F* Sachin Shinde          */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane       */
/* REVISION: 9.1    LAST MODIFIED: 06/28/00 BY: *N0DM* Mudit Mehta            */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* myb                    */
/* REVISION: 9.1    LAST MODIFIED: 10/05/00 BY: *N0VN* Mudit Mehta            */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.18.2.6       BY: Rajesh Thomas    DATE: 08/14/01  ECO: *M1H5*  */
/* Revision: 1.18.2.7       BY: Jean Miller      DATE: 05/22/02  ECO: *P074*  */
/* $Revision: 1.18.2.8 $             BY: Vivek Gogte      DATE: 08/06/02  ECO: *N1QQ*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}
{cxcustom.i "REPKIS.P"}

{gldydef.i new}
{gldynrm.i new}

define new shared variable nbr as character format "x(10)" label "Picklist".
define new shared variable eff_date like mfc_date.
define new shared variable use-to-loc-status like mfc_logical
   label "Use To Location Status" no-undo.
define new shared variable multi_entry like mfc_logical label "Multi Entry"
   no-undo.
define new shared variable cline as character.
define new shared variable lotserial_control like pt_lot_ser.
define new shared variable issue_or_receipt as character.
define new shared variable total_lotserial_qty like sr_qty.
define new shared variable site like sr_site no-undo.
define new shared variable location like sr_loc no-undo.
define new shared variable lotserial like sr_lotser no-undo.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable trans_um like pt_um.
define new shared variable trans_conv like sod_um_conv.
define new shared variable transtype as character.
define new shared variable lotref like sr_ref no-undo.

define variable disp_qopen as decimal no-undo.
define variable disp_all   as decimal no-undo.
define variable disp_pick  as decimal no-undo.
define variable disp_chg   as decimal no-undo.

{&REPKIS-P-TAG1}
define variable i as integer.
define variable undo-input like mfc_logical.
define variable seq as integer format ">>>" label "Sequence".
define variable lotnext like wo_lot_next .
define variable lotprcpt like wo_lot_rcpt no-undo.
define variable oldnbr like nbr no-undo.
define variable line like op_wkctr.
define variable wkctr like op_wkctr.
define variable comp like ps_comp.
define variable prod_site like lad_site.
define variable alloc like mfc_logical label "Alloc" initial yes.
define variable picked like mfc_logical label "Picked" initial yes.
define variable part like lad_part.
define variable qopen like lad_qty_all.
define variable yn like mfc_logical.

define shared variable global_recid as recid.

issue_or_receipt = getTermLabel("ISSUE",8).

/* THE FRAME E IS DEFINED SO THAT THE COMPONENTS BEING */
/* TRANSFERRED ARE NOT DISPLAYED ON THE SAME LINE.     */

define frame e
   line
   lad_part
   sr_site
   sr_loc
   sr_lotser
   sr_qty
with down no-attr-space width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame e:handle).

{gpglefv.i}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
space(1)
   prod_site
   nbr
   seq
   alloc
   picked
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
space(1)
   eff_date
   use-to-loc-status
   space(2)
 SKIP(.4)  /*GUI*/
with frame b centered row 4 overlay side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

FORM /*GUI*/  with frame c 6 down no-attr-space width 80 THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
line           colon 13       lotserial_qty  colon 53 pt_um
   part           colon 13       site           colon 53 location label "Loc"
   pt_desc1       colon 13       lotserial      colon 53
   pt_desc2       at 15 no-label lotref         colon 53
   multi_entry    colon 53
 SKIP(.4)  /*GUI*/
with frame d side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-d-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame d = F-d-title.
 RECT-FRAME-LABEL:HIDDEN in frame d = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame d =
  FRAME d:HEIGHT-PIXELS - RECT-FRAME:Y in frame d - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME d = FRAME d:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame d:handle).

/* GLOBAL_ADDR IS INITIALISED TO BLANK WHICH PREVENTS */
/* ASSIGNMENT OF ADDRESS FROM PREVIOUS TRANSACTION.   */

assign
   eff_date          = today
   use-to-loc-status = yes
   nbr               = ""
   prod_site         = global_site
   global_addr       = ""
   transtype         = "ISS-TR".

/* DISPLAY */
mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


assign
   nbr  = oldnbr
   part = ""
   line = "".

   view frame a.
   view frame c.
   view frame d.

   display
      prod_site
      nbr
      seq
      alloc
      picked
   with frame a.

   setsite:
   do on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      global_recid = ?.
      set
         prod_site
         nbr
         seq
         alloc
         picked
      with frame a editing:

         if frame-field = "prod_site"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i lad_det
                      lad_det
                     "lad_dataset = ""rps_det"""
                      substring(lad_nbr,1,8)
                      prod_site}
            if recno <> ?
            then
               display substring(lad_nbr,1,8) @ prod_site with frame a.
            recno = ?.
         end.
         else if frame-field = "nbr"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i lad_det
                      lad_det
                     "lad_dataset = ""rps_det"" and
                      lad_nbr begins string(input prod_site,""x(8)"") "
                      substring(lad_nbr,1,18)
                     "string(input prod_site,""x(8)"")
                    + string(input nbr,""x(10)"") "}

            if global_recid <> ?
            then
               find lad_det where
                  recid(lad_det) = global_recid
               no-lock no-error.

            if recno <> ? or
            (global_recid <> ? and available lad_det)
            then
               display
                  substring(lad_nbr,9) @ nbr
                  substring(lad_nbr,1,8) @ prod_site
                  substring(lad_nbr,19) format "x(3)" @ seq
               with frame a.
            assign
               recno        = ?
               global_recid = ?.
         end.
         else if frame-field = "seq"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i lad_det
                      lad_det
                     "lad_dataset = ""rps_det"" and
                      lad_nbr begins string(input prod_site,""x(8)"")
                    + string(input nbr,""x(10)"") "
                      lad_nbr
                     "string(input prod_site,""x(8)"")
                    + string(input nbr,""x(10)"")
                    + string(input seq,""999"") "}
            if recno <> ?
            then
               display substring(lad_nbr,19) format "x(3)" @ seq with frame a.
            recno = ?.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end. /* EDITING */

      if not can-find(si_mstr where si_site = prod_site)
      then do:
         /* SITE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
         next-prompt prod_site.
         undo, retry.
      end.

      {gprun.i ""gpsiver.p"" "(input prod_site,
           input ?,
           output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      if return_int = 0
      then do:
         /* USER DOES NOT HAVE ACCESS TO THIS SITE */
         {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
         next-prompt prod_site with frame a.
         undo, retry.
      end.

      if not can-find(first lad_det where lad_dataset = "rps_det"
         and lad_nbr begins prod_site)
      then do:
         /* REFERENCE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=1156 &ERRORLEVEL=3}
         next-prompt prod_site.
         undo, retry.
      end.

      find first lad_det no-lock where
         lad_dataset = "rps_det" and
         lad_nbr begins string(prod_site,"x(8)") + nbr
      no-error.

      if seq <> 0
      then
         find first lad_det no-lock where
            lad_dataset = "rps_det" and
            lad_nbr     = string(prod_site,"x(8)") + string(nbr,"x(10)")
                          + string(seq,"999")
         no-error.

      if not available lad_det
      then do:
         /* REFERENCE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=1156 &ERRORLEVEL=3}
         next-prompt nbr.
         undo, retry.
      end.

      if seq = 0 and
         substring(lad_nbr,19) <> ""
      then
         seq = integer(substring(lad_nbr,19)).
      display seq with frame a.
      pause 0.

      if eff_date = ?
      then
         eff_date = today.

      setb:
      do with frame b on error undo:
/*GUI*/ if global-beam-me-up then undo, leave.

         update
            eff_date
            use-to-loc-status.
         /* CHECK EFFECTIVE DATE */

         find si_mstr where si_site = prod_site no-lock.
         {gpglef1.i &module = ""IC""
                    &entity = si_entity
                    &date   = eff_date
                    &prompt = "eff_date"
                    &frame  = "b"
                    &loop   = "setb"
            }
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* SETSITE:  DO: */

   assign
      oldnbr = nbr
      nbr    = string(prod_site,"x(8)") + nbr.
   if seq <> 0
   then
      nbr = string(nbr,"x(18)") + string(seq,"999").

   {gprun.i ""repkisb.p"" "(nbr, prod_site, alloc, picked)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   setd:
   do while true:

      /* DISPLAY DETAIL */
      repeat:
         clear frame c all no-pause.
         clear frame d all no-pause.
         view frame c.
         view frame d.

         for each lad_det no-lock
            where lad_dataset = "rps_det"
            and lad_nbr       = nbr
            and lad_line     >= line
            and lad_part     >= part
         break by lad_dataset by lad_nbr by lad_line by lad_part by lad_site:

            qopen = lad_qty_all + lad_qty_pick.
            accumulate qopen (total by lad_part).
            accumulate lad_qty_all (total by lad_part).
            accumulate lad_qty_pick (total by lad_part).
            accumulate lad_qty_chg (total by lad_part).

            if not last-of (lad_part) then next.

            assign
               disp_qopen = accum total by lad_part qopen
               disp_all   = accum total by lad_part lad_qty_all
               disp_pick  = accum total by lad_part lad_qty_pick
               disp_chg   = accum total by lad_part lad_qty_chg.

            display
               lad_line   @ line
               lad_part
               disp_qopen format "->>>>>>>9.9<<<<<<<" label "Qty Open"
               disp_all   format "->>>>>>>9.9<<<<<<<" label "Qty Alloc"
               disp_pick  format "->>>>>>>9.9<<<<<<<" label "Qty Picked"
               disp_chg   format "->>>>>>>9.9<<<<<<<" label "Qty to Iss"
            with frame c.

            if frame-line(c) = frame-down(c) then leave.
            down 1 with frame c.
         end.

         input clear.

         hide frame b no-pause.

         run setline.

         /* TO RELEASE LOCKING OF WINDOWS WHEN ALT+X OR        */
         /* EXIT OR WINDOW CLOSE BUTTON X IS CLICKED, BEING IN */
         /* LINE FRAME OF WINDOWS VERSION.                     */
               if global-beam-me-up then undo mainloop, leave mainloop.    

         if return-value = "undo" then leave.

      end. /* REPEAT:  (DISPLAY DETAIL) */

      do on endkey undo mainloop, retry mainloop:
         yn = yes.
         /* DISPLAY WO LINES BEING SHIPPED? */
         {pxmsg.i &MSGNUM=636 &ERRORLEVEL=1 &CONFIRM=yn &CONFIRM-TYPE='LOGICAL'}
         if yn = yes
         then do:
            hide frame c no-pause.
            hide frame d no-pause.

            /* ADDED CHECK FOR lad_qty_chg TO DISPLAY WORK CENTER */
            /* AND PART FOR ALL COMPONENTS IN ISSUE SCREEN.       */

            for each lad_det
               fields(lad_dataset lad_line lad_loc lad_lot lad_nbr lad_part
                      lad_qty_all lad_qty_chg lad_qty_pick lad_ref lad_site)
               where lad_dataset = "rps_det"
               and   lad_nbr     =  nbr
               and   lad_qty_chg <> 0
             no-lock break by lad_dataset by lad_nbr by lad_line by lad_part
             with frame e:

               for each sr_wkfl no-lock where
                  sr_userid = mfguser  and
                  sr_lineid = string(lad_line,"x(8)") + "::" + lad_part and
                  sr_site   = lad_site and
                  sr_loc    = lad_loc  and
                  sr_lotser = lad_lot  and
                  sr_ref    = lad_ref
               with frame e:

                  if first-of (lad_part) or frame-line < 2
                  then
                     display
                        lad_line @ line
                        lad_part.

                  display
                     sr_site
                     sr_loc
                     sr_lotser
                     sr_qty.

                  if sr_ref > ""
                  then do:
                     down 1.
                     display getTermLabel("REFERENCE",8) + ": " +
                                sr_ref @ sr_lotser.
                  end. /* IF SR_REF > ... */
               end. /* FOR EACH SR_WKFL ...*/
            end. /* FOR EACH LAD_DET ... */
         end. /* IF YN = YES ... */
      end.  /* DO ON ENDKEY... */

      do on endkey undo mainloop, retry mainloop:
         yn = yes.

         /* IS ALL INFO CORRECT? */
         {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn &CONFIRM-TYPE='LOGICAL'}
              
         if yn = ? then undo mainloop, retry mainloop.   

         if yn
         then do:

            for each lad_det no-lock where
               lad_dataset = "rps_det" and
               lad_nbr     = nbr
            break by lad_dataset by lad_nbr by lad_line by lad_part:
/*GUI*/ if global-beam-me-up then undo, leave.


               for each sr_wkfl no-lock where
                  sr_userid = mfguser and
                  sr_lineid = string(lad_line,"x(8)") + "::" + lad_part and
                  sr_site   = lad_site and
                  sr_loc    = lad_loc and
                  sr_lotser = lad_lot and
                  sr_ref    = lad_ref
               with width 80:
/*GUI*/ if global-beam-me-up then undo, leave.


                  find pt_mstr where pt_part = lad_part no-lock no-error.

                  {gprun.i ""icedit.p"" " (""ISS-TR"",
                      sr_site,
                      sr_loc,
                      lad_part,
                      sr_lotser,
                      sr_ref,
                      sr_qty,
                      pt_um,
                      """",
                      """",
                      output undo-input )" }
/*GUI*/ if global-beam-me-up then undo, leave.


                  if not undo-input
                  then do:

                     {gprun.i ""icedit.p"" " (""RCT-TR"",
                         lad_site,
                         lad_line,
                         lad_part,
                         sr_lotser,
                         sr_ref,
                         sr_qty,
                         pt_um,
                         """",
                         """",
                         output undo-input )" }
/*GUI*/ if global-beam-me-up then undo, leave.

                  end.

                  if undo-input
                  then do:
                     assign
                        line = lad_line
                        part = lad_part.
                     next setd.
                  end.

                  /* VALIDATE GRADE ASSAY EXPIRE & INVENTORY STATUS */
                  {gprun.i ""repkisc.p""
                     "(input sr_site,
                       input lad_site,
                       input sr_loc,
                       input lad_line,
                       input lad_part,
                       input sr_lotser,
                       input sr_ref,
                       input sr_qty,
                       input use-to-loc-status,
                       output undo-input)" }
/*GUI*/ if global-beam-me-up then undo, leave.


                  if undo-input
                  then do:
                     assign
                        line = lad_line
                        part = lad_part.
                     next setd.
                  end.

               end.
/*GUI*/ if global-beam-me-up then undo, leave.

            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            {&REPKIS-P-TAG2}
            hide frame c.
            hide frame d.
            leave setd.
         end.
      end.  /* DO ON ENDKEY... */
   end. /* SETD:  DO WHILE TRUE: */

   {gprun.i ""repkisa.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


   nbr = substring(nbr,9).

end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* MAINLOOP */

/* DELETE STRANDED sr_wkfl and lad_det RECORDS */

for each sr_wkfl
   where sr_userid = mfguser
exclusive-lock:
   delete sr_wkfl.
end. /* FOR EACH sr_wkfl */

for each lad_det
    where lad_dataset  = "rps_det"
    and   lad_nbr     >=  string(prod_site,"x(8)")
                          + string(oldnbr,"x(10)")
    and   lad_nbr     <=  string(prod_site,"x(8)")
                          + string(oldnbr,"x(10)")
                          + hi_char
    and   lad_qty_all  = 0
    and   lad_qty_pick = 0
exclusive-lock:
   delete lad_det.
end. /* FOR EACH lad_det */

/*********START INTERNAL PROCEDURE LOGIC*************/

PROCEDURE setline:

   setline:
   do on error undo, retry on endkey undo, return "undo":
/*GUI*/ if global-beam-me-up then undo, leave.


      update
         line
         part
      with frame d editing:
         if frame-field = "line"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i
               lad_det
               lad_det
              "lad_dataset = ""rps_det"" and lad_nbr = nbr"
               lad_line
               line}
            if recno <> ?
            then do:
               assign
                  line = lad_line
                  part = lad_part.
               display
                  line
                  part
               with frame d.
            end.
         end.
         else if frame-field = "part"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp05.i
               lad_det
               lad_det
              "lad_dataset = ""rps_det"" and
               lad_nbr     = nbr         and
               lad_line    = line"
               lad_part
               part}
            if recno <> ?
            then do:
               part = lad_part.
               display part with frame d.
            end.
            recno = ?.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.

         find pt_mstr where pt_part = part no-lock no-error.
         if available pt_mstr
         then
            display
               pt_um
               pt_desc1
               pt_desc2
            with frame d.

         display
            "" @ lotserial_qty
            "" @ site
            "" @ location
            "" @ lotserial
            "" @ lotref
            "" @ multi_entry
         with frame d.

      end. /* UPDATE...EDITING */
      status input.

      if part = "" then leave.

      multi_entry = no.

      find first lad_det where
         lad_dataset = "rps_det" and
         lad_nbr     = nbr       and
         lad_line    = line      and
         lad_part    = part
      no-error.
      if not available lad_det
      then do:

         find first wc_mstr no-lock where wc_wkctr = line no-error.
         if not available wc_mstr
         then do:
         /* WORK CENTER/MACHINE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=519 &ERRORLEVEL=3}
            undo, retry.
         end.

         find first loc_mstr no-lock where loc_loc = line no-error.
         if not available loc_mstr
         then do:
            /* LOCATION DOES NOT EXIST */
            {pxmsg.i &MSGNUM=709 &ERRORLEVEL=3}
            undo, retry.
         end.

         find pt_mstr where pt_part = part no-lock no-error.
         if not available pt_mstr
         then do:
            /* ITEM NUMBER DOES NOT EXIST */
            {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            undo, retry.
         end.

         /* COMPONENT DOES NOT EXIST ON THIS WORK ORDER. */
         {pxmsg.i &MSGNUM=517 &ERRORLEVEL=2}

         create lad_det.
         assign
            lad_dataset = "rps_det"
            lad_nbr     = nbr
            lad_line    = line
            lad_part    = part
            lad_site    = prod_site.

         if recid(lad_det) = -1 then .
      end. /* IF NOT AVAILABLE LAD_DET */

      find pt_mstr where pt_part = lad_part no-lock no-error.
      if not available pt_mstr
      then do with frame d:
         /* ITEM NUMBER DOES NOT EXIST */
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=2}
         display part
            " " @ pt_um
            " " @ pt_desc1
            " " @ pt_desc2.
      end.
      else do with frame d:
         display
            pt_part @ part
            pt_um
            pt_desc1
            pt_desc2.
      end.

      assign
         qopen         = 0
         lotserial_qty = 0.
      for each lad_det
         where lad_dataset = "rps_det"
         and   lad_nbr     = nbr
         and   lad_line    = line
         and   lad_part    = part
      no-lock:
         assign
            qopen         = qopen + lad_qty_all + lad_qty_pick
            lotserial_qty = lad_qty_chg + lotserial_qty.
      end.
      assign
         total_lotserial_qty = lotserial_qty
         lotserial_control   = "".

      if available pt_mstr
      then
         lotserial_control = pt_lot_ser.
      assign
         site        = ""
         location    = ""
         lotserial   = ""
         lotref      = ""
         cline       = string(line,"x(8)") + "::" + part
         global_part = part.

      find first sr_wkfl no-lock
         where sr_userid = mfguser
         and   sr_lineid = cline
      no-error.
      if not available sr_wkfl
      then do:
         find first lad_det
            where lad_dataset = "rps_det"
            and   lad_nbr     = nbr
            and   lad_line    = line
            and   lad_part    = part
         no-error.
         assign
            site     = lad_site
            location = lad_loc.
      end.
      else do:
         find sr_wkfl
            where sr_userid = mfguser
            and   sr_lineid = cline
         no-lock no-error.
         if available sr_wkfl
         then
            assign
               site      = sr_site
               location  = sr_loc
               lotserial = sr_lotser
               lotref    = sr_ref.
         else
            multi_entry = yes.
      end.

      setrest:
      do on error undo, retry on endkey undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


         update
            lotserial_qty
            site
            location
            lotserial
            lotref
            multi_entry
         with frame d editing:
            assign
               global_site = input site
               global_loc = input location.
            readkey.
            apply lastkey.
         end.

         i = 0.
         for each sr_wkfl
            where sr_userid = mfguser
            and   sr_lineid = cline
         no-lock:
            i = i + 1.
            if i > 1
            then do:
               multi_entry = yes.
               leave.
            end.
         end.
         assign
            trans_um   = if available pt_mstr then pt_um else ""
            trans_conv = 1.

         if multi_entry
         then do:
            if i >= 1
            then do:
               assign
                  site      = ""
                  location  = ""
                  lotserial = ""
                  lotref    = "".
            end.
            assign
               lotnext  = ""
               lotprcpt = no.

            {gprun.i ""repksrup.p"" "(input prod_site,
                 input line,
                 input use-to-loc-status,
                 input """",
                 input """",
                 input-output lotnext,
                 input lotprcpt)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         end. /* IF MULTI_ENRY */
         else do:

            if lotserial_qty <> 0
            then do:

               {gprun.i ""icedit.p"" "(input ""ISS-TR"",
                    input site,
                    input location,
                    input global_part,
                    input lotserial,
                    input lotref,
                    input lotserial_qty,
                    input trans_um,
                    input """",
                    input """",
                    output undo-input
                    )" }
/*GUI*/ if global-beam-me-up then undo, leave.


               if undo-input then undo, retry.

               {gprun.i ""repkisc.p""
                  "(input site,
                    input prod_site,
                    input location,
                    input line,
                    input global_part,
                    input lotserial,
                    input lotref,
                    input lotserial_qty,
                    input use-to-loc-status,
                    output undo-input)" }
/*GUI*/ if global-beam-me-up then undo, leave.


               if undo-input then undo, retry.

            end. /* if lotserial_qty <> 0 */

            find first sr_wkfl
               where sr_userid = mfguser
               and   sr_lineid = cline
            no-error.
            if lotserial_qty <> 0
            then do:
               if not available sr_wkfl
               then
                  create sr_wkfl.
               assign
                  sr_userid = mfguser
                  sr_lineid = cline
                  sr_site   = site
                  sr_loc    = location
                  sr_lotser = lotserial
                  sr_ref    = lotref
                  sr_qty    = lotserial_qty
                  sr_rev    = line
                  sr_user2  = part.

               if recid(sr_wkfl) = -1 then .
            end.  /*lotserial_qty <> */
            else
            if available sr_wkfl and lotserial_qty = 0
            then
               delete sr_wkf.

         end.  /* (NOT MULTI_ENRY) */

         for each lad_det
            where lad_dataset = "rps_det"
            and   lad_nbr     = nbr
            and   lad_line    = line
            and lad_part      = part
         exclusive-lock:
            if can-find (sr_wkfl where sr_userid = mfguser
               and sr_lineid = cline
               and sr_site   = lad_site
               and sr_loc    = lad_loc
               and sr_lotser = lad_lot
               and sr_ref    = lad_ref)
            then next.
            lad_qty_chg = 0.
         end.

         for each sr_wkfl
            where sr_userid = mfguser
            and   sr_lineid = cline
         no-lock:
            find lad_det
               where lad_dataset = "rps_det"
               and   lad_nbr     = nbr
               and   lad_line    = line
               and   lad_part    = part
               and   lad_site    = sr_site
               and   lad_loc     = sr_loc
               and   lad_lot     = sr_lot
               and   lad_ref     = sr_ref
            no-error.
            if available lad_det
            then do:
               if lad_qty_chg <> sr_qty
               then
                  lad_qty_chg = sr_qty.
            end.
            else do:
               create lad_det.
               assign
                  lad_dataset = "rps_det"
                  lad_nbr     = nbr
                  lad_line    = line
                  lad_part    = part
                  lad_site    = sr_site
                  lad_loc     = sr_loc
                  lad_lot     = sr_lot
                  lad_ref     = sr_ref
                  lad_qty_chg = sr_qty
                  recno       = recid(lad_det).
            end.
         end.  /* EACH SR_WKFL */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* SETREST: DO: */
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* SETLINE: DO: */

END PROCEDURE. /* PROCEDURE setline */
